#include "query_result.h"
#include <string.h>

namespace engine
{
	DataField::DataField() : mValue(NULL), mType(DB_TYPE_UNKNOWN)
	{
	}

	DataField::DataField(DataField &f)
	{
		const char *value;

		value = f.getString();

		if (value && (mValue = new char[strlen(value) + 1]))
			strcpy(mValue, value);
		else
			mValue = NULL;

		mType = f.getType();
	}

	DataField::DataField(const char *value, enum DataField::DataTypes type) : mType(type)
	{
		if (value && (mValue = new char[strlen(value) + 1]))
			strcpy(mValue, value);
		else
			mValue = NULL;
	}

	DataField::~DataField()
	{
		if (mValue) delete [] mValue;
	}

	void DataField::setValue(const char *value)
	{
		if(mValue) delete [] mValue;

		if (value)
		{
			mValue = new char[strlen(value) + 1];
			strcpy(mValue, value);
		}
		else
			mValue = NULL;
	}
}
